//
// Created by xili on 2024/8/7 16:53.
// Go big or go home.
//
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>

using namespace std;

class Solution {
public:
    string frequencySort(string s) {
        unordered_map<char, int> ump;
        for (auto &item: s) {
            ump[item]++;
        }
        vector<pair<char, int>> v;
        for (auto &item: ump) {
            v.emplace_back(item);
        }
        sort(v.begin(), v.end(),
             [](const pair<char, int> &a, const pair<char, int> &b) { return a.second > b.second; });
        string ans;
        for (auto &[ch, num]: v) {
            for (int i = 0; i < num; i++) {
                ans.push_back(ch);
            }
        }
        return ans;
    }
};